package jnpf.engine.service.impl;

import cn.hutool.core.bean.BeanUtil;
import jnpf.base.UserInfo;
import jnpf.base.service.SuperServiceImpl;
import jnpf.engine.entity.FlowOperatorLogEntity;
import jnpf.engine.mapper.FlowOperatorLogMapper;
import jnpf.engine.model.open.FlowOperatorLogReq;
import jnpf.engine.service.FlowOperatorLogService;
import jnpf.util.IpUtil;
import jnpf.util.UserProvider;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class FlowOperatorLogServiceImpl extends SuperServiceImpl<FlowOperatorLogMapper, FlowOperatorLogEntity> implements FlowOperatorLogService {

    public final UserProvider userProvider;

    @Override
    public void log(FlowOperatorLogReq flowOperatorLogReq) {
        FlowOperatorLogEntity insert = new FlowOperatorLogEntity();
        BeanUtil.copyProperties(flowOperatorLogReq, insert);
        UserInfo userInfo = userProvider.get();
        insert.setUserName(userInfo.getUserName());
        insert.setIpAddress(IpUtil.getIpAddr());
        save(insert);
    }
}
